/*	******************************************
	File:		StateSoundTest.cpp
	Author:		Adnan Srna, Peter Kober, Ivo Havranek
	Purpose:	AugmentedReality 2
	(up)Date:	March/April 2010
	Descr.:		demo for our sound interface
	Origin:		Salzburg University of Applied Science
	******************************************	*/

#include "StateSoundTest.h"
#include "StateVideoTest.h"
#include "StateGame.h"

StateSoundTest::StateSoundTest(){
	ofAddListener(ofEvents.keyPressed, this, &StateSoundTest::keyPressed );
}

StateSoundTest::~StateSoundTest(){
	ofRemoveListener(ofEvents.keyPressed, this, &StateSoundTest::keyPressed );
	ofSoundStreamStop();
	music.stop();
	//ofAppGlutWindow::exitApp();
}

void StateSoundTest::setup(StateManager* _manager)
{
	manager = _manager;
	
	ofBackground(25, 11, 96);
	guiText.loadFont("calibri.ttf", 12, false, false, true);
	music.loadSound("SecretShame.mp3", true);
	music.play();
	music.setPosition(0.0777);
	mPlaying = true;

	soundTool.setup();
}


void StateSoundTest::update(){
	soundTool.update();
}


void StateSoundTest::draw(){
	drawGUI();
	soundTool.draw();
}


// check the keyboard input
void StateSoundTest::keyPressed(ofKeyEventArgs& arg)
{
	switch(arg.key){
		case '2':
			changeState(manager, new StateVideoTest());
			break;
		case '3':
			changeState(manager, new StateGame());
			break;
		case 'm':
			if(mPlaying == true){
				music.setPaused(true);
				mPos = music.getPosition();
				mPlaying = false;
			}

			else if(mPlaying == false) {
				music.setPaused(false);
				music.play();
				music.setPosition(mPos);
				mPlaying = true;
			}
			break;
		case 'q':
			ofAppGlutWindow::exitApp();
			break;
	}
}

void StateSoundTest::drawGUI(){
	ofSetColor(255, 255, 255);
	char tmpAmp[255];

	guiText.drawString("mmt08/HavI,KobP,SrnA - Demo for Sound Interface -", 50, 15);
	guiText.drawString("press [2]FaceTracking, [3]Game", 50, 40);
	
	sprintf(tmpAmp, "Sound Amplitude: %f",	soundTool.amplitude);
	guiText.drawString(tmpAmp, 50, ofGetHeight()-15);

	guiText.drawString("toggle [m]usic", 300, ofGetHeight()-15);
}
